<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <form id="cjtSystemEmailInfoForm" id="cjtSystemEmailInfoForm">
          <div class="layui-form-item">
            <label class="layui-form-label">CLIENTID</label>
            <div class="layui-input-block">
              <input type="text" name="yzAppkey" class="layui-input" lay-verify="required" required />
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">SECRET</label>
            <div class="layui-input-block">
              <input type="text" name="yzAppsecret" class="layui-input" lay-verify="required" required />
            </div>
          </div>
          <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="cjtsystemEmailInfoFormSubmit" lay-submit>保存</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <style>
    #systemEmailInfoForm .layui-form-label {
      width: 125px;
      padding-left: 0;
    }
    #systemEmailInfoForm .layui-input-block {
      margin-left: 150px;
    }
  </style>
  <!-- js部分 -->
  <script>
    layui.use(["layer", "form", "table", "admin"], function () {
      var $ = layui.jquery;
      var layer = layui.layer;
      var form = layui.form;
      var admin = layui.admin;
      list();

      
  
      //初始化表单
      function list() {
        admin.req(
          "enterprise/system/admin/systemLoginInfoTwo/list",
          { order:'desc',},
          function (res) {
            if (res.data[0]) {
              $('input[name="yzAppkey"]').val(res.data[0].yzAppkey || "");
              $('input[name="yzAppsecret"]').val(res.data[0].yzAppsecret || "");
            }
            console.log(res.data[0]);
            form.render();
          },
          "GET"
        );
      }
      // 表单提交事件
      form.on("submit(systemEmailInfoFormSubmit)", function (d) {
        if ($("#id").val() != "") {
          admin.req(
            "enterprise/system/admin/systemEmailInfo/update",
            d.field,
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
              list();
            },
            "PUT"
          );
        } else {
          admin.req(
            "enterprise/system/admin/systemEmailInfo/add",
            d.field,
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
              list();
            },
            "POST"
          );
        }
  
        return false;
      });
      form.on("submit(cjtsystemEmailInfoFormSubmit)", function (d) {
        const formData = {
          yzAppkey: $('input[name="yzAppkey"]').val(),
          yzAppsecret: $('input[name="yzAppsecret"]').val(),
        };

        admin.req(
            "enterprise/system/admin/systemLoginInfo/add",
            formData,  // 使用直接获取的键值对
            function (res) {
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
              console.log(res);
            },
            "POST"
          );
        return false;
      });
    });
  </script>
  